package com.test.wog.dao;

import com.test.wog.util.HttpRequestUtil;
import com.test.wog.util.PropertyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LX
 * @since 2020-01-30
 *
 */
@Repository
public class RouteDAOImpl implements RouteDAO{
    @Autowired
    PropertyUtil pu;
    @Autowired
    HttpRequestUtil hu;
    @Override
    public JSONObject getRouteFromAmapByLoc(double sLon, double sLat, double eLon, double eLat, String sTime) {
        Map<String, String> param = new HashMap<>();
        param.put("key", pu.getProjectConfig("key"));//传入API-KEY
        param.put("origin", sLon + "," + sLat);
        param.put("destination", eLon + "," + eLat);
        param.put("city", "北京");//目前仅考虑北京、先不管张家口
        String dateTime[] = sTime.split(" ");//该API的date和time是分离的
        param.put("date", dateTime[0]);
        param.put("time", dateTime[1]);
        JSONObject jo = hu.getJSONFromWebAPI(pu.getProjectConfig("route-api"), param);//根据配置文件中的路径url
        return jo;
    }

    @Override
    public JSONObject getDriveRouteFromAmapByLoc(double sLon, double sLat, double eLon, double eLat, String sTime) {
        return null;
    }
}
